#! /usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Mosson"
# 任务文件的文件名 必须是 tasks.py
import logging
from django.conf import settings
from rest_framework.response import Response
from luffyapi.settings import constants
from luffyapi.libs.yuntongxun.sendtemplatesms import YunTongXin
from mycelery.main import app

log = logging.getLogger("django")


@app.task(name="send_sms")
def send_sms(mobile, sms_code):
    """ 发送短信 """
    settings.SMS["templateId"] = constants.SMS_TEMPLATE_ID
    yun = YunTongXin(**settings.SMS)
    res = yun.run(mobile, sms_code)
    if res["statusCode"] != "000000":
        log.error("{}发送短信失败，错误码{}".format(mobile, res["statusCode"]))

    return "hello world！"
